#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
using namespace std;


class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        set<char> rigster;
        int left = 0;
        int right =  0;
        int result = 0;
        while (right<s.size())
        {
            if(rigster.insert(s[right]).second){
                ++right;
            }
            else{
                result = max(result,right-left);
                rigster.erase(s[left]);
                ++left;
            }
            
        }

        result = max(result,right-left);
        return result;
    }
};

int main(){
    Solution S;
    string s = "pwwkew";
    cout<<S.lengthOfLongestSubstring(s)<<endl;
}